#!/bin/bash


echo "-***********************************-"
echo "超牛X HDFS落地日志去重行数统计脚本启动"
echo "-***********************************-"

# 去当前日期的前一天日期
dt=$(date -d'-1 day' +%Y-%m-%d)

# 如果传入了参数，就用参数指定的日期
if [ $1 ]
then
dt=$1
fi

echo "处理的数据日期为: $dt"

sql="
insert into ods.user_action_log partition(dt='${dt}')
select
    username
    ,app_id
    ,app_version
    ,carrier
    ,device_id
    ,device_type
    ,event_id
    ,ip
    ,latitude
    ,longitude
    ,net_type
    ,os_name
    ,os_version
    ,properties
    ,release_channel
    ,resolution
    ,session_id
    ,action_time
from  tmp.user_action_log where dt='${dt}'
group by
    username
    ,app_id
    ,app_version
    ,carrier
    ,device_id
    ,device_type
    ,event_id
    ,ip
    ,latitude
    ,longitude
    ,net_type
    ,os_name
    ,os_version
    ,properties
    ,release_channel
    ,resolution
    ,session_id
    ,action_time
"

hive -e "$sql"